﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KZ400B;
using DB.DBUtility;
namespace Test
{
    class Program
    {

        static void testProtocolString()
        {
            Axle axle = new Axle("A");
            byte v1 = 0,v2 = 0;
            if (Verify.Compute("#X:OK", ref v1, ref v2) == ErrorCode.Success)
            {
                Console.WriteLine("#X:OK|{0}{1}", (char)v1, (char)v2);
            }
            if (Verify.Compute("=#X:OK", ref v1, ref v2) == ErrorCode.Success)
            {
                Console.WriteLine("=#X:OK|{0}{1}", (char)v1, (char)v2);
            }
            Console.WriteLine("{0}:{1}",CommFunctionCode.Contact.ToString(),Protocol.GetContactString());
            Console.WriteLine("{0}:{1}", CommFunctionCode.ParameterSetting.ToString()
                                        , Protocol.GetParameterSettingString("X"
                                            ,Axle.Direction.ForwardDirection
                                            ,axle.RunPWM
                                            ,200)
                                        );
            Console.WriteLine("{0}:{1}", CommFunctionCode.ParameterSetting.ToString()
                                        , Protocol.GetParameterSettingString("X"
                                            , Axle.Direction.ForwardDirection
                                            , axle.RunPWM
                                            , 200)
                                        );


            Console.WriteLine("{0}:{1}", CommFunctionCode.AccelerationSetting.ToString()
                        , Protocol.GetAccelerationSettingString("X"
                                , Axle.AccelerationLevel.AccelerationLevelConstant)
                        );
            Console.WriteLine("{0}:{1}", CommFunctionCode.AccelerationSetting.ToString()
            , Protocol.GetAccelerationSettingString("X"
                    , Axle.AccelerationLevel.AccelerationLevelGatherWay)
            );


            List<string> allList = new List<string>();
            allList.Add("X");
            allList.Add("Y");
            allList.Add("Z");
            allList.Add("T");
            allList.Add("U");
            allList.Add("W");

            Console.WriteLine("{0}:{1}", CommFunctionCode.Run.ToString(), Protocol.GetRunString("X"));
            Console.WriteLine("{0}:{1}", CommFunctionCode.Run.ToString(), Protocol.GetRunString(allList));

            Console.WriteLine("{0}:{1}", CommFunctionCode.Stop.ToString(), Protocol.GetStopString("X"));
            Console.WriteLine("{0}:{1}", CommFunctionCode.Stop.ToString(), Protocol.GetStopString(allList));

            Console.WriteLine("{0}:{1}", CommFunctionCode.ToZero.ToString()
                , Protocol.GetToZeroString("X",axle.TozeroPWM)
                );
            Console.WriteLine("{0}:{1}", CommFunctionCode.ToZero.ToString()
                , Protocol.GetToZeroString("X", axle.TozeroPWM)
                );

            Console.WriteLine("{0}:{1}", CommFunctionCode.Query.ToString(), Protocol.GetQueryPostionString("X"));
            Console.WriteLine("{0}:{1}", CommFunctionCode.Query.ToString(), Protocol.GetQuerySuccessString());

            //AxleManager.normalSingleResponse("=OKMG>");
            //AxleManager.normalSingleResponse("=ERRBF>");

            Protocol.UnpackAction("=#GX:OKMC>");

            double xd = 123456.789123f;
            Console.WriteLine(xd.ToString("#.000"));
            Console.WriteLine(xd.ToString("#.###"));


            xd = 123456;
            Console.WriteLine(xd.ToString("#.000"));
            Console.WriteLine(xd.ToString("#.###"));

        }

        static bool changeTPlanStepRunDistance()
        {
            string sql = @"ALTER TABLE `TAxle`.`TPlanStep`
  CHANGE COLUMN `RunDistance` `RunDistance` double NOT NULL DEFAULT 0 COMMENT '运行距离';";

            int rows = DbHelperMySQL.ExecuteSql(sql);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }

        }
        static void Main(string[] args)
        {

            //Axle.RunningSpeed rSpeed = new Axle.RunningSpeed( 1 );
            //testProtocolString();

            bool rst = changeTPlanStepRunDistance();
            Console.WriteLine("update {0}", rst ? "complete" : "failed");

            Console.WriteLine("press any key to exit");
            //Console.ReadLine();
        }
    }
}
